package com.yanqu.road.server.cmd.union;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.pb.union.UnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.UnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.utils.string.StringUtils;

//@Cmd(code = Protocol.S_UNION_DETAIL, desc = "联盟详细信息")
public class GetUnionDetailCmd extends AbstractCommand {

	private String unionUid;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		unionUid = player.getUserInfo().getUnionUid();
		if (!StringUtils.isNullOrEmpty(unionUid)) {
			UnionMgr.updateMemberInfo(player, unionUid);
			UnionMgr.judgeChangeUnionOwner(player, unionUid);
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		UnionProto.UnionDetailMsg.Builder respMsg = UnionMgr.getUnionDetailMsg(unionUid, eUnionSyncType.Normal.getValue());
//		if (!StringUtils.isNullOrEmpty(unionUid)) {
//			respMsg.getUnionBuilder().setWinTimes(CrossDataMgr.getUnionWinTimes(unionId));
//		}
		player.sendPacket(Protocol.U_UNION_DETAIL, respMsg);
	}

}
